<?php

class DataflowAction extends Action {
    public function index(){
    	//总合数据不准在action重新统计
    	if ($_POST['startdate']&&$_POST['enddate']){//时间间查询
    			$this->date_sum($_POST['startdate'], $_POST['enddate']);	
    	}elseif($_POST['in_pv_ip_uv']){//排序
//    		dump($_SESSION['volist']);
    		foreach ($_SESSION['volist'] as $key => $row) {
			    $volume[$key]  = $row[$_POST['in_pv_ip_uv']];  
			}
			array_multisort($volume, SORT_DESC, $_SESSION['volist']);
    	}elseif($_GET['link_date']){//最近几天数据
    		if($_GET['link_date']==1){//昨天的数据
    			$tmp=time() - 86400*1;
    		}
    		if($_GET['link_date']==7){//7天的数据
    			$tmp=time() - 86400*7;
    		}
    		if($_GET['link_date']==30){//30天的数据
    			$tmp=time() - 86400*30;
    		}
    			$enddate=date("Y-m-d",time());
				$startdate=date("Y-m-d",$tmp);
    		if($_GET['link_date']==1){//昨天的数据
    			$enddate=$startdate;
    		}				
				$this->date_sum($startdate, $enddate);
    	}else {
				$app_sort=3;
				$info_model=M('App_info');
    			if ($_POST['category_select']=="1"){
					$app_sort=1;
					$map="app_sort=".$app_sort;
				}
    			if ($_POST['category_select']=="2"){
					$app_sort=2;
					$map="app_sort=".$app_sort;
				}
		    	if ($_POST['guanjianzi']){
		    		$map['app_name'] = array('like','%'.$_POST['guanjianzi'].'%');	
		    	}

		    	$this->_list($info_model,$map);
		    	

		    	$time=time();
		    	$app_date_tm=date("Y-m-d",$time);
		    	foreach ($_SESSION['volist'] as $key => $value){
		    		$app_table_ip="app_table_ip_".$value['id'];
					$app_table_ip_model = M($app_table_ip); 
					$app_table_ip_info=$app_table_ip_model->where("app_date='".$app_date_tm."'")->select();
					if (!$app_table_ip_info){
						$app_table_ip_info_aggregate_val=0;
					}else {
						for($nubmer_h=1;$nubmer_h<24;$nubmer_h++){
								if ($nubmer_h<10){
									$nubmer_h="0".$nubmer_h;
								}
								$app_table_ip_info_aggregate[$nubmer_h]=$app_table_ip_info[0][$nubmer_h];	
							}
							$app_table_ip_info_aggregate_val=array_sum($app_table_ip_info_aggregate);
							if ($app_table_ip_info_aggregate_val!=$app_table_ip_info[0]['aggregate']){
								$app_table_data['aggregate'] = $app_table_ip_info_aggregate_val;
								$app_table_map['app_date']=$app_date_tm;
								$app_table_ip_model->where($app_table_map)->save($app_table_data);
							}
					}
		    		$_SESSION['volist'][$key]['ip']=$app_table_ip_info_aggregate_val;
		    		
		    		$app_table_pv="app_table_pv_".$value['id'];
					$app_table_pv_model = M($app_table_pv); 
					$app_table_pv_info=$app_table_pv_model->where("app_date='".$app_date_tm."'")->select();
					if (!$app_table_pv_info){
						$app_table_pv_info_aggregate_val=0;
					}else {
						for($nubmer_h=1;$nubmer_h<24;$nubmer_h++){
								if ($nubmer_h<10){
									$nubmer_h="0".$nubmer_h;
								}
								$app_table_pv_info_aggregate[$nubmer_h]=$app_table_pv_info[0][$nubmer_h];	
							}
							$app_table_pv_info_aggregate_val=array_sum($app_table_pv_info_aggregate);
							if ($app_table_pv_info_aggregate_val!=$app_table_pv_info[0]['aggregate']){
								$app_table_data['aggregate'] = $app_table_pv_info_aggregate_val;
								$app_table_map['app_date']=$app_date_tm;
								$app_table_pv_model->where($app_table_map)->save($app_table_data);
							}
					}
		    		$_SESSION['volist'][$key]['pv']=$app_table_pv_info_aggregate_val;
		    		
		    		$app_table_uv="app_table_uv_".$value['id'];
					$app_table_uv_model = M($app_table_uv); 
					$app_table_uv_info=$app_table_uv_model->where("app_date='".$app_date_tm."'")->select();
					if (!$app_table_uv_info){
						$app_table_uv_info_aggregate_val=0;
					}else {
						for($nubmer_h=1;$nubmer_h<24;$nubmer_h++){
								if ($nubmer_h<10){
									$nubmer_h="0".$nubmer_h;
								}
								$app_table_uv_info_aggregate[$nubmer_h]=$app_table_uv_info[0][$nubmer_h];	
							}
							$app_table_uv_info_aggregate_val=array_sum($app_table_uv_info_aggregate);
							if ($app_table_uv_info_aggregate_val!=$app_table_uv_info[0]['aggregate']){
								$app_table_data['aggregate'] = $app_table_uv_info_aggregate_val;
								$app_table_map['app_date']=$app_date_tm;
								$app_table_uv_model->where($app_table_map)->save($app_table_data);
							}
					}
		    		$_SESSION['volist'][$key]['uv']=$app_table_uv_info_aggregate_val;
		    	}	
    	}
    	
    	  foreach ($_SESSION['volist'] as  $row) {
				   		$all_total_pv[]=$row['pv'];
				   		$all_total_ip[]=$row['ip'];
				   		$all_total_uv[]=$row['uv'];
				   		  
					}  
//dump($_SESSION['volist']);
		$this->assign('all_total_pv',array_sum($all_total_pv));
		$this->assign('all_total_ip',array_sum($all_total_ip));
		$this->assign('all_total_uv',array_sum($all_total_uv));
    	$this->assign('list',$_SESSION['volist']);// 赋值数据集
    	$this->assign('app_sort',$app_sort);
    	$this->display();
    }
    
    public function view_index(){
    	
    	if($_GET['app_id']){
		    	$app_id=$_GET['app_id'];
		   		 $time=time();
		   		 if ($_POST['startdate']){
		   		 	$app_date_tm=$_POST['startdate'];
		   		 }else {
		   		 	$app_date_tm=date("Y-m-d",$time);
		   		 }
		    	
		    	
		    	$info_model=M('App_info');
		    	$info_map['id']=$app_id;
		    	$info_result=$info_model->where($info_map)->select();
		    	$app_name=$info_result[0]["app_name"];
		    	

		  	  	$app_table_pv="app_table_pv_".$app_id;
				$app_table_pv_model = M($app_table_pv); 
				$app_table_pv_info=$app_table_pv_model->where("app_date='".$app_date_tm."'")->select();
				if (!$app_table_pv_info){
//					$this->error(L('验证码错误').' [ <a href="javascript:history.back(-2)">return</a> ]');
					echo "<script type='text/javascript'>alert('没有当天数据');</script>";
					$this->assign('show_date',$_SESSION['show_date']);
					$this->assign('app_id',$app_id);
					$this->assign('app_name',$app_name);
					$this->assign('view_html',$_SESSION['filename']);
					$this->assign('link_info_num_list',$_SESSION['link_info_num_list']);
					$this->assign('list',$_SESSION['day_list']);// 赋值数据集
					$this->display();
//					exit();
				}
				$_SESSION['show_date']=$app_date_tm;
				$_SESSION['yScaleMax']=$app_table_pv_info[0]['aggregate'];
		    	foreach ($app_table_pv_info as $key => $row_pv) {   		
			    		$row_pv_val=$row_pv;
				}
		    	
		    	$app_table_ip="app_table_ip_".$app_id;
				$app_table_ip_model = M($app_table_ip); 
				$app_table_ip_info=$app_table_ip_model->where("app_date='".$app_date_tm."'")->select();		
		    	foreach ($app_table_ip_info as $key => $row_ip) {  		
			    		$row_ip_val=$row_ip;
				}
				
		   	 	$app_table_uv="app_table_uv_".$app_id;
				$app_table_uv_model = M($app_table_uv); 
				$app_table_uv_info=$app_table_uv_model->where("app_date='".$app_date_tm."'")->select();		
		    	foreach ($app_table_uv_info as $key => $row_uv) {  		
			    		$row_uv_val=$row_uv;
				}
					
					$_SESSION['day_list']=array('01'=>array('id_h'=>'01','pv'=>$row_pv_val['01'],'ip'=>$row_ip_val['01'],'uv'=>$row_uv_val['01']),
			    								'02'=>array('id_h'=>'02','pv'=>$row_pv_val['02'],'ip'=>$row_ip_val['02'],'uv'=>$row_uv_val['02']),
			    								'03'=>array('id_h'=>'03','pv'=>$row_pv_val['03'],'ip'=>$row_ip_val['03'],'uv'=>$row_uv_val['03']),
			    								'04'=>array('id_h'=>'04','pv'=>$row_pv_val['04'],'ip'=>$row_ip_val['04'],'uv'=>$row_uv_val['04']),
										    	'05'=>array('id_h'=>'05','pv'=>$row_pv_val['05'],'ip'=>$row_ip_val['05'],'uv'=>$row_uv_val['05']),
										    	'06'=>array('id_h'=>'06','pv'=>$row_pv_val['06'],'ip'=>$row_ip_val['06'],'uv'=>$row_uv_val['06']),
										    	'07'=>array('id_h'=>'07','pv'=>$row_pv_val['07'],'ip'=>$row_ip_val['07'],'uv'=>$row_uv_val['07']),
										    	'08'=>array('id_h'=>'08','pv'=>$row_pv_val['08'],'ip'=>$row_ip_val['08'],'uv'=>$row_uv_val['08']),
										    	'09'=>array('id_h'=>'09','pv'=>$row_pv_val['09'],'ip'=>$row_ip_val['09'],'uv'=>$row_uv_val['09']),
										    	'10'=>array('id_h'=>'10','pv'=>$row_pv_val['10'],'ip'=>$row_ip_val['10'],'uv'=>$row_uv_val['10']),
										    	'11'=>array('id_h'=>'11','pv'=>$row_pv_val['11'],'ip'=>$row_ip_val['11'],'uv'=>$row_uv_val['11']),
										    	'12'=>array('id_h'=>'12','pv'=>$row_pv_val['12'],'ip'=>$row_ip_val['12'],'uv'=>$row_uv_val['12']),
										    	'13'=>array('id_h'=>'13','pv'=>$row_pv_val['13'],'ip'=>$row_ip_val['13'],'uv'=>$row_uv_val['13']),
										    	'14'=>array('id_h'=>'14','pv'=>$row_pv_val['14'],'ip'=>$row_ip_val['14'],'uv'=>$row_uv_val['14']),
										    	'15'=>array('id_h'=>'15','pv'=>$row_pv_val['15'],'ip'=>$row_ip_val['15'],'uv'=>$row_uv_val['15']),
										    	'16'=>array('id_h'=>'16','pv'=>$row_pv_val['16'],'ip'=>$row_ip_val['16'],'uv'=>$row_uv_val['16']),
										    	'17'=>array('id_h'=>'17','pv'=>$row_pv_val['17'],'ip'=>$row_ip_val['17'],'uv'=>$row_uv_val['17']),
										    	'18'=>array('id_h'=>'18','pv'=>$row_pv_val['18'],'ip'=>$row_ip_val['18'],'uv'=>$row_uv_val['18']),
										    	'19'=>array('id_h'=>'19','pv'=>$row_pv_val['19'],'ip'=>$row_ip_val['19'],'uv'=>$row_uv_val['19']),
										    	'20'=>array('id_h'=>'20','pv'=>$row_pv_val['20'],'ip'=>$row_ip_val['20'],'uv'=>$row_uv_val['20']),
										    	'21'=>array('id_h'=>'21','pv'=>$row_pv_val['21'],'ip'=>$row_ip_val['21'],'uv'=>$row_uv_val['21']),
										    	'22'=>array('id_h'=>'22','pv'=>$row_pv_val['22'],'ip'=>$row_ip_val['22'],'uv'=>$row_uv_val['22']),
										    	'23'=>array('id_h'=>'23','pv'=>$row_pv_val['23'],'ip'=>$row_ip_val['23'],'uv'=>$row_uv_val['23']),
												'24'=>array('id_h'=>'24','pv'=>$row_pv_val['24'],'ip'=>$row_ip_val['24'],'uv'=>$row_uv_val['24']),
			    								);
			   //链接
			   $app_link_model=M('app_link');
			   $app_link_info=$app_link_model->where("app_id='".$app_id."'")->select();
			   /**
			    * link-1
			    */
 /*   			if ($app_link_info[0]['app_link_ad1']){
    				$ad_start=$app_link_info[0]['app_link_start1'];
    				if ($app_link_info[0]['app_link_sed1']<24&&$app_link_info[0]['app_link_start1']<$app_link_info[0]['app_link_sed1']){
    					$ad_sed=$app_link_info[0]['app_link_sed1'];
    				}else {
    					$ad_sed=24;
    				}
    				if ($ad_start){
				   		for ($ad_start;$ad_start<=$ad_sed;$ad_start++){
				   			if ($ad_start<10){
				  				$ad_start="0".$ad_start;
				  			}
					   		$link_info_num1[]=$_SESSION['day_list'][$ad_start];
					   	}
    				}
    				if ($app_link_info[0]['app_link_start1']>$app_link_info[0]['app_link_sed1']){
	    				for ($i=1;$i<=$app_link_info[0]['app_link_sed1'];$i++){
				  			if ($i<10){
				  				$i="0".$i;
				  			}
				  			$link_info_num1[]=$_SESSION['day_list'][$i];
					   	}
    				}
			  		
				   foreach ($link_info_num1 as  $row) {
				   		$link_pv1[]=$row['pv'];
				   		$link_ip1[]=$row['ip'];
				   		$link_uv1[]=$row['uv'];
				   		  
					}  
					$link_info_num_list[$app_link_info[0]['app_link_alias1']]['link']=$app_link_info[0]['app_link_ad1'];
					$link_info_num_list[$app_link_info[0]['app_link_alias1']]['alias']=$app_link_info[0]['app_link_alias1'];
					$link_info_num_list[$app_link_info[0]['app_link_alias1']]['date']=$app_link_info[0]['app_link_start1']."-".$app_link_info[0]['app_link_sed1'];
					$link_info_num_list[$app_link_info[0]['app_link_alias1']]['pv']=array_sum($link_pv1);
					$link_info_num_list[$app_link_info[0]['app_link_alias1']]['ip']=array_sum($link_ip1);
					$link_info_num_list[$app_link_info[0]['app_link_alias1']]['uv']=array_sum($link_uv1);
			   }*/
  
			   /**
			    * link-2
			    */
/*    			if ($app_link_info[0]['app_link_ad2']){
    				$ad_start=$app_link_info[0]['app_link_start2'];
    				if ($app_link_info[0]['app_link_sed2']<24&&$app_link_info[0]['app_link_start2']<$app_link_info[0]['app_link_sed2']){
    					$ad_sed=$app_link_info[0]['app_link_sed2'];
    				}else {
    					$ad_sed=24;
    				}
    				if ($ad_start){
				   		for ($ad_start;$ad_start<=$ad_sed;$ad_start++){
				   			if ($ad_start<10){
				  				$ad_start="0".$ad_start;
				  			}
					   		$link_info_num2[]=$_SESSION['day_list'][$ad_start];
					   	}
    				}
    				
    				if ($app_link_info[0]['app_link_start2']>$app_link_info[0]['app_link_sed2']){
	    				for ($i=1;$i<=$app_link_info[0]['app_link_sed2'];$i++){
				  			if ($i<10){
				  				$i="0".$i;
				  			}
				  			$link_info_num2[]=$_SESSION['day_list'][$i];
					   	}
    				}
			  		
				   foreach ($link_info_num2 as  $row) {
				   		$link_pv2[]=$row['pv'];
				   		$link_ip2[]=$row['ip'];
				   		$link_uv2[]=$row['uv'];
				   		  
					}  
					$link_info_num_list[$app_link_info[0]['app_link_alias2']]['link']=$app_link_info[0]['app_link_ad2'];
					$link_info_num_list[$app_link_info[0]['app_link_alias2']]['alias']=$app_link_info[0]['app_link_alias2'];
					$link_info_num_list[$app_link_info[0]['app_link_alias2']]['date']=$app_link_info[0]['app_link_start2']."-".$app_link_info[0]['app_link_sed2'];
					$link_info_num_list[$app_link_info[0]['app_link_alias2']]['pv']=array_sum($link_pv2);
					$link_info_num_list[$app_link_info[0]['app_link_alias2']]['ip']=array_sum($link_ip2);
					$link_info_num_list[$app_link_info[0]['app_link_alias2']]['uv']=array_sum($link_uv2);
			   }*/
			     
			   /**
			    * link-3
			    */
/*    			if ($app_link_info[0]['app_link_ad3']){
    				$ad_start=$app_link_info[0]['app_link_start3'];
    				if ($app_link_info[0]['app_link_sed3']<24&&$app_link_info[0]['app_link_start3']<$app_link_info[0]['app_link_sed3']){
    					$ad_sed=$app_link_info[0]['app_link_sed3'];
    				}else {
    					$ad_sed=24;
    				}
    				if ($ad_start){
				   		for ($ad_start;$ad_start<=$ad_sed;$ad_start++){
				   			if ($ad_start<10){
				  				$ad_start="0".$ad_start;
				  			}
					   		$link_info_num3[]=$_SESSION['day_list'][$ad_start];
					   	}
    				}
    				
    				if ($app_link_info[0]['app_link_start3']>$app_link_info[0]['app_link_sed3']){
	    				for ($i=1;$i<=$app_link_info[0]['app_link_sed3'];$i++){
				  			if ($i<10){
				  				$i="0".$i;
				  			}
				  			$link_info_num3[]=$_SESSION['day_list'][$i];
					   	}
    				}
			  		
				   foreach ($link_info_num3 as  $row) {
				   		$link_pv3[]=$row['pv'];
				   		$link_ip3[]=$row['ip'];
				   		$link_uv3[]=$row['uv'];
				   		  
					}  
					$link_info_num_list[$app_link_info[0]['app_link_alias3']]['link']=$app_link_info[0]['app_link_ad3'];
					$link_info_num_list[$app_link_info[0]['app_link_alias3']]['alias']=$app_link_info[0]['app_link_alias3'];
					$link_info_num_list[$app_link_info[0]['app_link_alias3']]['date']=$app_link_info[0]['app_link_start3']."-".$app_link_info[0]['app_link_sed3'];
					$link_info_num_list[$app_link_info[0]['app_link_alias3']]['pv']=array_sum($link_pv3);
					$link_info_num_list[$app_link_info[0]['app_link_alias3']]['ip']=array_sum($link_ip3);
					$link_info_num_list[$app_link_info[0]['app_link_alias3']]['uv']=array_sum($link_uv3);
			   }
			   */
			   /**
			    * link-4
			    */
/*    			if ($app_link_info[0]['app_link_ad4']){
    				$ad_start=$app_link_info[0]['app_link_start4'];
    				if ($app_link_info[0]['app_link_sed4']<24&&$app_link_info[0]['app_link_start4']<$app_link_info[0]['app_link_sed4']){
    					$ad_sed=$app_link_info[0]['app_link_sed4'];
    				}else {
    					$ad_sed=24;
    				}
    				if ($ad_start){
				   		for ($ad_start;$ad_start<=$ad_sed;$ad_start++){
				   			if ($ad_start<10){
				  				$ad_start="0".$ad_start;
				  			}
					   		$link_info_num4[]=$_SESSION['day_list'][$ad_start];
					   	}
    				}
    				
    				if ($app_link_info[0]['app_link_start4']>$app_link_info[0]['app_link_sed4']){
	    				for ($i=1;$i<=$app_link_info[0]['app_link_sed4'];$i++){
				  			if ($i<10){
				  				$i="0".$i;
				  			}
				  			$link_info_num4[]=$_SESSION['day_list'][$i];
					   	}
    				}
			  		
				   foreach ($link_info_num4 as  $row) {
				   		$link_pv4[]=$row['pv'];
				   		$link_ip4[]=$row['ip'];
				   		$link_uv4[]=$row['uv'];
				   		  
					}  
					$link_info_num_list[$app_link_info[0]['app_link_alias4']]['link']=$app_link_info[0]['app_link_ad4'];
					$link_info_num_list[$app_link_info[0]['app_link_alias4']]['alias']=$app_link_info[0]['app_link_alias4'];
					$link_info_num_list[$app_link_info[0]['app_link_alias4']]['date']=$app_link_info[0]['app_link_start4']."-".$app_link_info[0]['app_link_sed4'];
					$link_info_num_list[$app_link_info[0]['app_link_alias4']]['pv']=array_sum($link_pv4);
					$link_info_num_list[$app_link_info[0]['app_link_alias4']]['ip']=array_sum($link_ip4);
					$link_info_num_list[$app_link_info[0]['app_link_alias4']]['uv']=array_sum($link_uv4);
			   }
			   */
			   /**
			    * link-5
			    */
/*    			if ($app_link_info[0]['app_link_ad5']){
    				$ad_start=$app_link_info[0]['app_link_start5'];
    				if ($app_link_info[0]['app_link_sed5']<24&&$app_link_info[0]['app_link_start5']<$app_link_info[0]['app_link_sed5']){
    					$ad_sed=$app_link_info[0]['app_link_sed5'];
    				}else {
    					$ad_sed=24;
    				}
    				if ($ad_start){
				   		for ($ad_start;$ad_start<=$ad_sed;$ad_start++){
				   			if ($ad_start<10){
				  				$ad_start="0".$ad_start;
				  			}
					   		$link_info_num5[]=$_SESSION['day_list'][$ad_start];
					   	}
    				}
    				
    				if ($app_link_info[0]['app_link_start5']>$app_link_info[0]['app_link_sed5']){
	    				for ($i=1;$i<=$app_link_info[0]['app_link_sed5'];$i++){
				  			if ($i<10){
				  				$i="0".$i;
				  			}
				  			$link_info_num5[]=$_SESSION['day_list'][$i];
					   	}
    				}
			  		
				   foreach ($link_info_num5 as  $row) {
				   		$link_pv5[]=$row['pv'];
				   		$link_ip5[]=$row['ip'];
				   		$link_uv5[]=$row['uv'];
				   		  
					}  
					$link_info_num_list[$app_link_info[0]['app_link_alias5']]['link']=$app_link_info[0]['app_link_ad5'];
					$link_info_num_list[$app_link_info[0]['app_link_alias5']]['alias']=$app_link_info[0]['app_link_alias5'];
					$link_info_num_list[$app_link_info[0]['app_link_alias5']]['date']=$app_link_info[0]['app_link_start5']."-".$app_link_info[0]['app_link_sed5'];
					$link_info_num_list[$app_link_info[0]['app_link_alias5']]['pv']=array_sum($link_pv5);
					$link_info_num_list[$app_link_info[0]['app_link_alias5']]['ip']=array_sum($link_ip5);
					$link_info_num_list[$app_link_info[0]['app_link_alias5']]['uv']=array_sum($link_uv5);
			   }*/
			   
				$day_date=date('Y-m-d',$time);
		
				$link_date_model=M('App_link_date');
				$link_date_map['app_link_date_date']=$day_date;
				$link_date_map['app_link_id']=$app_id;
				$link_date_result=$link_date_model->where($link_date_map)->select();
				
				
    			foreach ($_SESSION['day_list'] as  $val) {
								
								$sum_pv_val[]=$val['pv'];
								$sum_ip_val[]=$val['ip'];
								$sum_uv_val[]=$val['uv'];
					    }
				$sum_pv=array_sum($sum_pv_val);//24小时pv和
				$sum_ip=array_sum($sum_ip_val);//24小时ip和
				$sum_uv=array_sum($sum_uv_val);//24小时uv和
				
				$link_history_data_model=M('App_link_history_data');
				
				for($link_date_i=1;$link_date_i<=5;$link_date_i++){
					if ($link_date_result[0]['app_link_date_start'.$link_date_i]&&$link_date_result[0]['app_link_date_send'.$link_date_i]){
						
						$link_history_map['history_data_date']=$day_date;
						$link_history_map['history_data_app_id']=$app_id;
						$link_history_map['history_data_date_start']=$link_date_result[0]['app_link_date_start'.$link_date_i];
						$link_history_map['history_data_date_send']=$link_date_result[0]['app_link_date_send'.$link_date_i];
						
						$link_history_result=$link_history_data_model->where($link_history_map)->select();
						
						$link_info_num_list[$link_date_i]['alias']=$link_history_result[0]["history_data_alias"];//别名
						$link_info_num_list[$link_date_i]['date']=$link_history_result[0]["history_data_time_range"];
						
						$array_slice_quval=$link_date_result[0]['app_link_date_send'.$link_date_i]-$link_date_result[0]['app_link_date_start'.$link_date_i];
						$output = array_slice($_SESSION['day_list'], $link_date_result[0]['app_link_date_start'.$link_date_i]-1, $array_slice_quval+1,true);
					    foreach ($output as  $val) {
		
					    	$link_pv[$link_date_i][]=$val['pv'];
					    	$link_ip[$link_date_i][]=$val['ip'];
						   	$link_uv[$link_date_i][]=$val['uv'];
					    }
					    
					    $between_sum_pv=array_sum($link_pv[$link_date_i]);
					    $between_sum_ip=array_sum($link_ip[$link_date_i]);
					    $between_sum_uv=array_sum($link_uv[$link_date_i]);
					    
					    if ($link_date_result[0]['app_link_date_start'.$link_date_i]<=$link_date_result[0]['app_link_date_send'.$link_date_i]){
					    	$link_info_num_list[$link_date_i]['pv']=$between_sum_pv;
						    $link_info_num_list[$link_date_i]['ip']=$between_sum_ip;
						    $link_info_num_list[$link_date_i]['uv']=$between_sum_uv;
					    }else {
						    $link_info_num_list[$link_date_i]['pv']=$sum_pv-$between_sum_pv;
						    $link_info_num_list[$link_date_i]['ip']=$sum_ip-$between_sum_ip;
						    $link_info_num_list[$link_date_i]['uv']=$sum_uv-$between_sum_uv;
					    }
					    
					}
				}
 
			   $_SESSION['link_info_num_list']=$link_info_num_list;

   	    
    	    /**
    	     * 图
    	     */
			    	Vendor('jpgraph.jpgraph');
			    	Vendor('jpgraph.jpgraph_line');
			    	$aAxisType = 'intlin'; //第一个int是X轴类型第2个lin是Y轴类型
					$yScaleMin = 0; //Y轴最小值, 如果不需要设置，可以为空，或者NULL，下同
					$yScaleMax = $_SESSION['yScaleMax']; //Y轴最大值
					$xScaleMin = 1; //X轴最大值
					$xScaleMax = 24; //X轴最大值
					
					$unitType = '小时';
					
					  $chartDataTmpArr = array('1' =>$_SESSION['day_list']['01']['pv'], 
					  							'2' =>$_SESSION['day_list']['02']['pv'], 
					  							'3' =>$_SESSION['day_list']['03']['pv'], 
					  							'4' =>$_SESSION['day_list']['04']['pv'], 
					  							'5' =>$_SESSION['day_list']['05']['pv'], 
					  							'6' =>$_SESSION['day_list']['06']['pv'], 
					  							'7' =>$_SESSION['day_list']['07']['pv'], 
					  							'8' =>$_SESSION['day_list']['08']['pv'], 
					  							'9' => $_SESSION['day_list']['09']['pv'], 
					  							'10' =>$_SESSION['day_list']['10']['pv'], 
					  							'11' =>$_SESSION['day_list']['11']['pv'], 
					  							'12' =>$_SESSION['day_list']['12']['pv'], 
					  							'13' =>$_SESSION['day_list']['13']['pv'], 
					  							'14' =>$_SESSION['day_list']['14']['pv'], 
					  							'15' =>$_SESSION['day_list']['15']['pv'], 
					  							'16' =>$_SESSION['day_list']['16']['pv'], 
					  							'17' =>$_SESSION['day_list']['17']['pv'], 
					  							'18' =>$_SESSION['day_list']['18']['pv'], 
					  							'19' =>$_SESSION['day_list']['19']['pv'], 
					  							'20' =>$_SESSION['day_list']['20']['pv'], 
					  							'21' =>$_SESSION['day_list']['21']['pv'], 
					  							'22' =>$_SESSION['day_list']['22']['pv'], 
					  							'23' =>$_SESSION['day_list']['23']['pv'], 
					  							'24' =>$_SESSION['day_list']['24']['pv'],
					  							'25' => '1000000000');
					
					$chartDataTmpArr2 = array('1' =>$_SESSION['day_list']['01']['ip'], 
					  							'2' =>$_SESSION['day_list']['02']['ip'], 
					  							'3' =>$_SESSION['day_list']['03']['ip'], 
					  							'4' =>$_SESSION['day_list']['04']['ip'], 
					  							'5' =>$_SESSION['day_list']['05']['ip'], 
					  							'6' =>$_SESSION['day_list']['06']['ip'], 
					  							'7' =>$_SESSION['day_list']['07']['ip'], 
					  							'8' =>$_SESSION['day_list']['08']['ip'], 
					  							'9' => $_SESSION['day_list']['09']['ip'], 
					  							'10' =>$_SESSION['day_list']['10']['ip'], 
					  							'11' =>$_SESSION['day_list']['11']['ip'], 
					  							'12' =>$_SESSION['day_list']['12']['ip'], 
					  							'13' =>$_SESSION['day_list']['13']['ip'], 
					  							'14' =>$_SESSION['day_list']['14']['ip'], 
					  							'15' =>$_SESSION['day_list']['15']['ip'], 
					  							'16' =>$_SESSION['day_list']['16']['ip'], 
					  							'17' =>$_SESSION['day_list']['17']['ip'], 
					  							'18' =>$_SESSION['day_list']['18']['ip'], 
					  							'19' =>$_SESSION['day_list']['19']['ip'], 
					  							'20' =>$_SESSION['day_list']['20']['ip'], 
					  							'21' =>$_SESSION['day_list']['21']['ip'], 
					  							'22' =>$_SESSION['day_list']['22']['ip'], 
					  							'23' =>$_SESSION['day_list']['23']['ip'], 
					  							'24' =>$_SESSION['day_list']['24']['ip'],
					  							'25' => '1000000000');		
					$chartDataTmpArr3 = array('1' =>$_SESSION['day_list']['01']['uv'], 
					  							'2' =>$_SESSION['day_list']['02']['uv'], 
					  							'3' =>$_SESSION['day_list']['03']['uv'], 
					  							'4' =>$_SESSION['day_list']['04']['uv'], 
					  							'5' =>$_SESSION['day_list']['05']['uv'], 
					  							'6' =>$_SESSION['day_list']['06']['uv'], 
					  							'7' =>$_SESSION['day_list']['07']['uv'], 
					  							'8' =>$_SESSION['day_list']['08']['uv'], 
					  							'9' => $_SESSION['day_list']['09']['uv'], 
					  							'10' =>$_SESSION['day_list']['10']['uv'], 
					  							'11' =>$_SESSION['day_list']['11']['uv'], 
					  							'12' =>$_SESSION['day_list']['12']['uv'], 
					  							'13' =>$_SESSION['day_list']['13']['uv'], 
					  							'14' =>$_SESSION['day_list']['14']['uv'], 
					  							'15' =>$_SESSION['day_list']['15']['uv'], 
					  							'16' =>$_SESSION['day_list']['16']['uv'], 
					  							'17' =>$_SESSION['day_list']['17']['uv'], 
					  							'18' =>$_SESSION['day_list']['18']['uv'], 
					  							'19' =>$_SESSION['day_list']['19']['uv'], 
					  							'20' =>$_SESSION['day_list']['20']['uv'], 
					  							'21' =>$_SESSION['day_list']['21']['uv'], 
					  							'22' =>$_SESSION['day_list']['22']['uv'], 
					  							'23' =>$_SESSION['day_list']['23']['uv'], 
					  							'24' =>$_SESSION['day_list']['24']['uv'],
					  							'25' => '1000000000');		
					$graph = new Graph($width = 750 , $height = 300); //创建新的Graph对象
					$graph->SetScale($aAxisType, $yScaleMin, $yScaleMax, $xScaleMin, $xScaleMax); //设置刻度模式SetScale($aAxisType,$aYMin=1,$aYMax=1,$aXMin=1,$aXMax=1)
					
					$graph->img->SetMargin(40, 20, 50, 50) ; //设置图表边界
					$title = date("Y-m-d H:i:s")."统计图";
					$graph->title->SetFont(FF_SIMSUN,FS_BOLD); //设置图表标题的字体类型
					$graph->title->Set($wholeTitle);
					$graph->title->SetMargin (20);
					
					$graph->xaxis->title->SetFont(FF_SIMSUN);
					$graph->xaxis->title->Set($unitType);
					$graph->xaxis->title->SetMargin(14);
					
					$graph->legend->SetLineWeight(2); //设置图例文字的字体 
					
					$lineplot = new LinePlot($chartDataTmpArr); //创建要画的一地条曲线的对象
					$lineplot->SetWeight(2); //曲线的线宽
					
					$lineplot->SetLegend("pv");//设置图例文字
					$graph->legend->Pos( 0.025, 0.08, "right","center" ); //图例文字框的位置 0.025，0.08 是以右上角为基准的，0.025是距左右距离，0.08是上下距离。
					$graph->legend->SetLayout('1'); //如果有两条曲线，他们的图例文字并排放置。
					$graph->legend->SetFrameWeight(0); //图例文字外框边框border设置为0
					$graph->legend->SetFillColor('#C8C8C8'); //图例文字框内的填充颜色
					$graph->legend->SetShadow('#C8C8C8', 0); //设置图例文字框的阴影部分颜色和border
					$lineplot->SetColor("orange"); //设置曲线颜色
					$graph->Add($lineplot); //在统计图上绘制曲线
					    
					$lineplot2 = new LinePlot($chartDataTmpArr2); //创建一条新的曲线对象
					$lineplot2->SetLegend("ip");
					$lineplot2->SetWeight(2);
					$lineplot2->SetColor("blue"); 
					$graph->Add($lineplot2);
					
					$lineplot3 = new LinePlot($chartDataTmpArr3); //创建一条新的曲线对象
					$lineplot3->SetLegend("uv");
					$lineplot3->SetWeight(2);
					$lineplot3->SetColor("red"); 
					$graph->Add($lineplot3);
					
					$_SESSION['filename']=THEME_PATH.'Public/images/strock/'.time().'.png';		
					$graph->Stroke($_SESSION['filename']);
			//		$view_html=$graph->Stroke();
    	    }
    	    if($_POST['in_pv_ip_uv']){//pv_ip_uv排序
    	    	foreach ($_SESSION['day_list'] as $key => $row) {
			    $volume[$key]  = $row[$_POST['in_pv_ip_uv']];  
				}
				array_multisort($volume, SORT_DESC, $_SESSION['day_list']);
    	    }
 
    	    		    	
//		dump($_SESSION['day_list']);
		$this->assign('show_date',$_SESSION['show_date']);
		$this->assign('app_id',$app_id);
		$this->assign('app_name',$app_name);
		$this->assign('view_html',$_SESSION['filename']);
		$this->assign('link_info_num_list',$_SESSION['link_info_num_list']);
		$this->assign('list',$_SESSION['day_list']);// 赋值数据集
		$this->display();
    }
    
    public function day_view_index(){
    	//http://www.oschina.net/code/snippet_221301_8700
    	if($_GET['app_id']){
		    	$app_id=$_GET['app_id'];
		    	
		    	$info_model=M('App_info');
		    	$info_map['id']=$app_id;
		    	$info_result=$info_model->where($info_map)->select();
		    	$app_name=$info_result[0]["app_name"];
    	}
    	
    	if ($_POST['startdate']&&$_POST['enddate']){
    		$startdate=$_POST['startdate'];
    		$enddate=$_POST['enddate'];
    		$data_map['app_date'] = array('between', array($startdate, $enddate));
    	}
    	
    	
    	
    	$app_table_pv="app_table_pv_".$app_id;
		$app_table_pv_model = M($app_table_pv); 
//		$app_table_pv_info=$app_table_pv_model->order('app_date desc')->select();
		$this->_list2($app_table_pv_model,$data_map);
//		dump($_SESSION['volist2']);
		
		$i=0;
		foreach ($_SESSION['volist2'] as $val){
				$app_table_pv_each['app_date']=$val["app_date"];
				$app_table_pv_each['pv_aggregate']=$val["aggregate"];
				
				$app_table_ip="app_table_ip_".$app_id;
				$app_table_ip_model = M($app_table_ip); 
				$app_table_ip_info=$app_table_ip_model->where("app_date='".$val["app_date"]."'")->select();	
				$app_table_pv_each['ip_aggregate']=$app_table_ip_info[0]['aggregate'];
				if (empty($app_table_pv_each['ip_aggregate'])){
					$app_table_pv_each['ip_aggregate']='0';
				}
				
				$app_table_uv="app_table_uv_".$app_id;
				$app_table_uv_model = M($app_table_uv); 
				$app_table_uv_info=$app_table_uv_model->where("app_date='".$val["app_date"]."'")->select();	
				$app_table_pv_each['uv_aggregate']=$app_table_uv_info[0]['aggregate'];
				if (empty($app_table_pv_each['uv_aggregate'])){
					$app_table_pv_each['uv_aggregate']='0';
				}
//				dump($app_table_ip_info[0]['aggregate']);exit();
				
				$app_table_pv_all[$i]=$app_table_pv_each;
				$i++;	
		}//dump($app_table_pv_all);
		
//$this->fenyie($app_table_pv_all);
		$this->assign('app_id',$app_id);
    	$this->assign('data_list',$app_table_pv_all);
    	$this->assign('app_name',$app_name);
    	$this->display();
    }
    
 	public function h_view_index(){
 		
    	if($_GET['app_id']&&$_GET['app_date_tm']){
    		
		    	$app_id=$_GET['app_id'];
		   		 $time=time();
    	 		if ($_POST['startdate']){
		   		 	$app_date_tm=$_POST['startdate'];
		   		 }else {
		   		 	$app_date_tm=$_GET['app_date_tm'];
		   		 }
		    	
		    	$info_model=M('App_info');
		    	$info_map['id']=$app_id;
		    	$info_result=$info_model->where($info_map)->select();
		    	$app_name=$info_result[0]["app_name"];
		    	
		    	
		  	  	$app_table_pv="app_table_pv_".$app_id;
				$app_table_pv_model = M($app_table_pv); 
				$app_table_pv_info=$app_table_pv_model->where("app_date='".$app_date_tm."'")->select();
    			if (!$app_table_pv_info){
//					$this->error(L('验证码错误').' [ <a href="javascript:history.back(-2)">return</a> ]');
					echo "<script type='text/javascript'>alert('没有当天数据');</script>";
					$this->assign('show_date',$_SESSION['show_date']);
					$this->assign('app_id',$app_id);
					$this->assign('app_name',$app_name);
					$this->assign('view_html',$_SESSION['filename']);
					$this->assign('link_info_num_list',$_SESSION['link_info_num_list']);
					$this->assign('list',$_SESSION['day_list']);// 赋值数据集
					$this->display();
//					exit();
				}
				$_SESSION['show_date']=$app_date_tm;
				$_SESSION['yScaleMax']=$app_table_pv_info[0]['aggregate'];
		    	foreach ($app_table_pv_info as $key => $row_pv) {   		
			    		$row_pv_val=$row_pv;
				}
		    	
		    	$app_table_ip="app_table_ip_".$app_id;
				$app_table_ip_model = M($app_table_ip); 
				$app_table_ip_info=$app_table_ip_model->where("app_date='".$app_date_tm."'")->select();		
		    	foreach ($app_table_ip_info as $key => $row_ip) {  		
			    		$row_ip_val=$row_ip;
				}
				
		   	 	$app_table_uv="app_table_uv_".$app_id;
				$app_table_uv_model = M($app_table_uv); 
				$app_table_uv_info=$app_table_uv_model->where("app_date='".$app_date_tm."'")->select();		
		    	foreach ($app_table_uv_info as $key => $row_uv) {  		
			    		$row_uv_val=$row_uv;
				}
					
					$_SESSION['day_list']=array('01'=>array('id_h'=>'01','pv'=>$row_pv_val['01'],'ip'=>$row_ip_val['01'],'uv'=>$row_uv_val['01']),
			    								'02'=>array('id_h'=>'02','pv'=>$row_pv_val['02'],'ip'=>$row_ip_val['02'],'uv'=>$row_uv_val['02']),
			    								'03'=>array('id_h'=>'03','pv'=>$row_pv_val['03'],'ip'=>$row_ip_val['03'],'uv'=>$row_uv_val['03']),
			    								'04'=>array('id_h'=>'04','pv'=>$row_pv_val['04'],'ip'=>$row_ip_val['04'],'uv'=>$row_uv_val['04']),
										    	'05'=>array('id_h'=>'05','pv'=>$row_pv_val['05'],'ip'=>$row_ip_val['05'],'uv'=>$row_uv_val['05']),
										    	'06'=>array('id_h'=>'06','pv'=>$row_pv_val['06'],'ip'=>$row_ip_val['06'],'uv'=>$row_uv_val['06']),
										    	'07'=>array('id_h'=>'07','pv'=>$row_pv_val['07'],'ip'=>$row_ip_val['07'],'uv'=>$row_uv_val['07']),
										    	'08'=>array('id_h'=>'08','pv'=>$row_pv_val['08'],'ip'=>$row_ip_val['08'],'uv'=>$row_uv_val['08']),
										    	'09'=>array('id_h'=>'09','pv'=>$row_pv_val['09'],'ip'=>$row_ip_val['09'],'uv'=>$row_uv_val['09']),
										    	'10'=>array('id_h'=>'10','pv'=>$row_pv_val['10'],'ip'=>$row_ip_val['10'],'uv'=>$row_uv_val['10']),
										    	'11'=>array('id_h'=>'11','pv'=>$row_pv_val['11'],'ip'=>$row_ip_val['11'],'uv'=>$row_uv_val['11']),
										    	'12'=>array('id_h'=>'12','pv'=>$row_pv_val['12'],'ip'=>$row_ip_val['12'],'uv'=>$row_uv_val['12']),
										    	'13'=>array('id_h'=>'13','pv'=>$row_pv_val['13'],'ip'=>$row_ip_val['13'],'uv'=>$row_uv_val['13']),
										    	'14'=>array('id_h'=>'14','pv'=>$row_pv_val['14'],'ip'=>$row_ip_val['14'],'uv'=>$row_uv_val['14']),
										    	'15'=>array('id_h'=>'15','pv'=>$row_pv_val['15'],'ip'=>$row_ip_val['15'],'uv'=>$row_uv_val['15']),
										    	'16'=>array('id_h'=>'16','pv'=>$row_pv_val['16'],'ip'=>$row_ip_val['16'],'uv'=>$row_uv_val['16']),
										    	'17'=>array('id_h'=>'17','pv'=>$row_pv_val['17'],'ip'=>$row_ip_val['17'],'uv'=>$row_uv_val['17']),
										    	'18'=>array('id_h'=>'18','pv'=>$row_pv_val['18'],'ip'=>$row_ip_val['18'],'uv'=>$row_uv_val['18']),
										    	'19'=>array('id_h'=>'19','pv'=>$row_pv_val['19'],'ip'=>$row_ip_val['19'],'uv'=>$row_uv_val['19']),
										    	'20'=>array('id_h'=>'20','pv'=>$row_pv_val['20'],'ip'=>$row_ip_val['20'],'uv'=>$row_uv_val['20']),
										    	'21'=>array('id_h'=>'21','pv'=>$row_pv_val['21'],'ip'=>$row_ip_val['21'],'uv'=>$row_uv_val['21']),
										    	'22'=>array('id_h'=>'22','pv'=>$row_pv_val['22'],'ip'=>$row_ip_val['22'],'uv'=>$row_uv_val['22']),
										    	'23'=>array('id_h'=>'23','pv'=>$row_pv_val['23'],'ip'=>$row_ip_val['23'],'uv'=>$row_uv_val['23']),
												'24'=>array('id_h'=>'24','pv'=>$row_pv_val['24'],'ip'=>$row_ip_val['24'],'uv'=>$row_uv_val['24']),
			    								);
			   //链接
			   $app_link_model=M('app_link');
			   $app_link_info=$app_link_model->where("app_id='".$app_id."'")->select();
			   /**
			    * link-1
			    */
 /*   			if ($app_link_info[0]['app_link_ad1']){
    				$ad_start=$app_link_info[0]['app_link_start1'];
    				if ($app_link_info[0]['app_link_sed1']<24&&$app_link_info[0]['app_link_start1']<$app_link_info[0]['app_link_sed1']){
    					$ad_sed=$app_link_info[0]['app_link_sed1'];
    				}else {
    					$ad_sed=24;
    				}
    				if ($ad_start){
				   		for ($ad_start;$ad_start<=$ad_sed;$ad_start++){
				   			if ($ad_start<10){
				  				$ad_start="0".$ad_start;
				  			}
					   		$link_info_num1[]=$_SESSION['day_list'][$ad_start];
					   	}
    				}
    				if ($app_link_info[0]['app_link_start1']>$app_link_info[0]['app_link_sed1']){
	    				for ($i=1;$i<=$app_link_info[0]['app_link_sed1'];$i++){
				  			if ($i<10){
				  				$i="0".$i;
				  			}
				  			$link_info_num1[]=$_SESSION['day_list'][$i];
					   	}
    				}
			  		
				   foreach ($link_info_num1 as  $row) {
				   		$link_pv1[]=$row['pv'];
				   		$link_ip1[]=$row['ip'];
				   		$link_uv1[]=$row['uv'];
				   		  
					}  
					$link_info_num_list[$app_link_info[0]['app_link_alias1']]['link']=$app_link_info[0]['app_link_ad1'];
					$link_info_num_list[$app_link_info[0]['app_link_alias1']]['alias']=$app_link_info[0]['app_link_alias1'];
					$link_info_num_list[$app_link_info[0]['app_link_alias1']]['date']=$app_link_info[0]['app_link_start1']."-".$app_link_info[0]['app_link_sed1'];
					$link_info_num_list[$app_link_info[0]['app_link_alias1']]['pv']=array_sum($link_pv1);
					$link_info_num_list[$app_link_info[0]['app_link_alias1']]['ip']=array_sum($link_ip1);
					$link_info_num_list[$app_link_info[0]['app_link_alias1']]['uv']=array_sum($link_uv1);
			   }*/
  
			   /**
			    * link-2
			    */
/*    			if ($app_link_info[0]['app_link_ad2']){
    				$ad_start=$app_link_info[0]['app_link_start2'];
    				if ($app_link_info[0]['app_link_sed2']<24&&$app_link_info[0]['app_link_start2']<$app_link_info[0]['app_link_sed2']){
    					$ad_sed=$app_link_info[0]['app_link_sed2'];
    				}else {
    					$ad_sed=24;
    				}
    				if ($ad_start){
				   		for ($ad_start;$ad_start<=$ad_sed;$ad_start++){
				   			if ($ad_start<10){
				  				$ad_start="0".$ad_start;
				  			}
					   		$link_info_num2[]=$_SESSION['day_list'][$ad_start];
					   	}
    				}
    				
    				if ($app_link_info[0]['app_link_start2']>$app_link_info[0]['app_link_sed2']){
	    				for ($i=1;$i<=$app_link_info[0]['app_link_sed2'];$i++){
				  			if ($i<10){
				  				$i="0".$i;
				  			}
				  			$link_info_num2[]=$_SESSION['day_list'][$i];
					   	}
    				}
			  		
				   foreach ($link_info_num2 as  $row) {
				   		$link_pv2[]=$row['pv'];
				   		$link_ip2[]=$row['ip'];
				   		$link_uv2[]=$row['uv'];
				   		  
					}  
					$link_info_num_list[$app_link_info[0]['app_link_alias2']]['link']=$app_link_info[0]['app_link_ad2'];
					$link_info_num_list[$app_link_info[0]['app_link_alias2']]['alias']=$app_link_info[0]['app_link_alias2'];
					$link_info_num_list[$app_link_info[0]['app_link_alias2']]['date']=$app_link_info[0]['app_link_start2']."-".$app_link_info[0]['app_link_sed2'];
					$link_info_num_list[$app_link_info[0]['app_link_alias2']]['pv']=array_sum($link_pv2);
					$link_info_num_list[$app_link_info[0]['app_link_alias2']]['ip']=array_sum($link_ip2);
					$link_info_num_list[$app_link_info[0]['app_link_alias2']]['uv']=array_sum($link_uv2);
			   }*/
			     
			   /**
			    * link-3
			    */
/*    			if ($app_link_info[0]['app_link_ad3']){
    				$ad_start=$app_link_info[0]['app_link_start3'];
    				if ($app_link_info[0]['app_link_sed3']<24&&$app_link_info[0]['app_link_start3']<$app_link_info[0]['app_link_sed3']){
    					$ad_sed=$app_link_info[0]['app_link_sed3'];
    				}else {
    					$ad_sed=24;
    				}
    				if ($ad_start){
				   		for ($ad_start;$ad_start<=$ad_sed;$ad_start++){
				   			if ($ad_start<10){
				  				$ad_start="0".$ad_start;
				  			}
					   		$link_info_num3[]=$_SESSION['day_list'][$ad_start];
					   	}
    				}
    				
    				if ($app_link_info[0]['app_link_start3']>$app_link_info[0]['app_link_sed3']){
	    				for ($i=1;$i<=$app_link_info[0]['app_link_sed3'];$i++){
				  			if ($i<10){
				  				$i="0".$i;
				  			}
				  			$link_info_num3[]=$_SESSION['day_list'][$i];
					   	}
    				}
			  		
				   foreach ($link_info_num3 as  $row) {
				   		$link_pv3[]=$row['pv'];
				   		$link_ip3[]=$row['ip'];
				   		$link_uv3[]=$row['uv'];
				   		  
					}  
					$link_info_num_list[$app_link_info[0]['app_link_alias3']]['link']=$app_link_info[0]['app_link_ad3'];
					$link_info_num_list[$app_link_info[0]['app_link_alias3']]['alias']=$app_link_info[0]['app_link_alias3'];
					$link_info_num_list[$app_link_info[0]['app_link_alias3']]['date']=$app_link_info[0]['app_link_start3']."-".$app_link_info[0]['app_link_sed3'];
					$link_info_num_list[$app_link_info[0]['app_link_alias3']]['pv']=array_sum($link_pv3);
					$link_info_num_list[$app_link_info[0]['app_link_alias3']]['ip']=array_sum($link_ip3);
					$link_info_num_list[$app_link_info[0]['app_link_alias3']]['uv']=array_sum($link_uv3);
			   }
			   */
			   /**
			    * link-4
			    */
/*    			if ($app_link_info[0]['app_link_ad4']){
    				$ad_start=$app_link_info[0]['app_link_start4'];
    				if ($app_link_info[0]['app_link_sed4']<24&&$app_link_info[0]['app_link_start4']<$app_link_info[0]['app_link_sed4']){
    					$ad_sed=$app_link_info[0]['app_link_sed4'];
    				}else {
    					$ad_sed=24;
    				}
    				if ($ad_start){
				   		for ($ad_start;$ad_start<=$ad_sed;$ad_start++){
				   			if ($ad_start<10){
				  				$ad_start="0".$ad_start;
				  			}
					   		$link_info_num4[]=$_SESSION['day_list'][$ad_start];
					   	}
    				}
    				
    				if ($app_link_info[0]['app_link_start4']>$app_link_info[0]['app_link_sed4']){
	    				for ($i=1;$i<=$app_link_info[0]['app_link_sed4'];$i++){
				  			if ($i<10){
				  				$i="0".$i;
				  			}
				  			$link_info_num4[]=$_SESSION['day_list'][$i];
					   	}
    				}
			  		
				   foreach ($link_info_num4 as  $row) {
				   		$link_pv4[]=$row['pv'];
				   		$link_ip4[]=$row['ip'];
				   		$link_uv4[]=$row['uv'];
				   		  
					}  
					$link_info_num_list[$app_link_info[0]['app_link_alias4']]['link']=$app_link_info[0]['app_link_ad4'];
					$link_info_num_list[$app_link_info[0]['app_link_alias4']]['alias']=$app_link_info[0]['app_link_alias4'];
					$link_info_num_list[$app_link_info[0]['app_link_alias4']]['date']=$app_link_info[0]['app_link_start4']."-".$app_link_info[0]['app_link_sed4'];
					$link_info_num_list[$app_link_info[0]['app_link_alias4']]['pv']=array_sum($link_pv4);
					$link_info_num_list[$app_link_info[0]['app_link_alias4']]['ip']=array_sum($link_ip4);
					$link_info_num_list[$app_link_info[0]['app_link_alias4']]['uv']=array_sum($link_uv4);
			   }
			   */
			   /**
			    * link-5
			    */
/*    			if ($app_link_info[0]['app_link_ad5']){
    				$ad_start=$app_link_info[0]['app_link_start5'];
    				if ($app_link_info[0]['app_link_sed5']<24&&$app_link_info[0]['app_link_start5']<$app_link_info[0]['app_link_sed5']){
    					$ad_sed=$app_link_info[0]['app_link_sed5'];
    				}else {
    					$ad_sed=24;
    				}
    				if ($ad_start){
				   		for ($ad_start;$ad_start<=$ad_sed;$ad_start++){
				   			if ($ad_start<10){
				  				$ad_start="0".$ad_start;
				  			}
					   		$link_info_num5[]=$_SESSION['day_list'][$ad_start];
					   	}
    				}
    				
    				if ($app_link_info[0]['app_link_start5']>$app_link_info[0]['app_link_sed5']){
	    				for ($i=1;$i<=$app_link_info[0]['app_link_sed5'];$i++){
				  			if ($i<10){
				  				$i="0".$i;
				  			}
				  			$link_info_num5[]=$_SESSION['day_list'][$i];
					   	}
    				}
			  		
				   foreach ($link_info_num5 as  $row) {
				   		$link_pv5[]=$row['pv'];
				   		$link_ip5[]=$row['ip'];
				   		$link_uv5[]=$row['uv'];
				   		  
					}  
					$link_info_num_list[$app_link_info[0]['app_link_alias5']]['link']=$app_link_info[0]['app_link_ad5'];
					$link_info_num_list[$app_link_info[0]['app_link_alias5']]['alias']=$app_link_info[0]['app_link_alias5'];
					$link_info_num_list[$app_link_info[0]['app_link_alias5']]['date']=$app_link_info[0]['app_link_start5']."-".$app_link_info[0]['app_link_sed5'];
					$link_info_num_list[$app_link_info[0]['app_link_alias5']]['pv']=array_sum($link_pv5);
					$link_info_num_list[$app_link_info[0]['app_link_alias5']]['ip']=array_sum($link_ip5);
					$link_info_num_list[$app_link_info[0]['app_link_alias5']]['uv']=array_sum($link_uv5);
			   }*/
			   
				$day_date=$_GET['app_date_tm'];
		
				$link_date_model=M('App_link_date');
				$link_date_map['app_link_date_date']=$day_date;
				$link_date_map['app_link_id']=$app_id;
				$link_date_result=$link_date_model->where($link_date_map)->select();
				
				
    			foreach ($_SESSION['day_list'] as  $val) {
								
								$sum_pv_val[]=$val['pv'];
								$sum_ip_val[]=$val['ip'];
								$sum_uv_val[]=$val['uv'];
					    }
				$sum_pv=array_sum($sum_pv_val);//24小时pv和
				$sum_ip=array_sum($sum_ip_val);//24小时ip和
				$sum_uv=array_sum($sum_uv_val);//24小时uv和
				
				$link_history_data_model=M('App_link_history_data');
				
				for($link_date_i=1;$link_date_i<=5;$link_date_i++){
					if ($link_date_result[0]['app_link_date_start'.$link_date_i]&&$link_date_result[0]['app_link_date_send'.$link_date_i]){
						
						$link_history_map['history_data_date']=$day_date;
						$link_history_map['history_data_app_id']=$app_id;
						$link_history_map['history_data_date_start']=$link_date_result[0]['app_link_date_start'.$link_date_i];
						$link_history_map['history_data_date_send']=$link_date_result[0]['app_link_date_send'.$link_date_i];
						
						$link_history_result=$link_history_data_model->where($link_history_map)->select();
						
						$link_info_num_list[$link_date_i]['alias']=$link_history_result[0]["history_data_alias"];//别名
						$link_info_num_list[$link_date_i]['date']=$link_history_result[0]["history_data_time_range"];
						
						$array_slice_quval=$link_date_result[0]['app_link_date_send'.$link_date_i]-$link_date_result[0]['app_link_date_start'.$link_date_i];
						$output = array_slice($_SESSION['day_list'], $link_date_result[0]['app_link_date_start'.$link_date_i]-1, $array_slice_quval+1,true);
					    foreach ($output as  $val) {
		
					    	$link_pv[$link_date_i][]=$val['pv'];
					    	$link_ip[$link_date_i][]=$val['ip'];
						   	$link_uv[$link_date_i][]=$val['uv'];
					    }
					    
					    $between_sum_pv=array_sum($link_pv[$link_date_i]);
					    $between_sum_ip=array_sum($link_ip[$link_date_i]);
					    $between_sum_uv=array_sum($link_uv[$link_date_i]);
					    
					    if ($link_date_result[0]['app_link_date_start'.$link_date_i]<=$link_date_result[0]['app_link_date_send'.$link_date_i]){
					    	$link_info_num_list[$link_date_i]['pv']=$between_sum_pv;
						    $link_info_num_list[$link_date_i]['ip']=$between_sum_ip;
						    $link_info_num_list[$link_date_i]['uv']=$between_sum_uv;
					    }else {
						    $link_info_num_list[$link_date_i]['pv']=$sum_pv-$between_sum_pv;
						    $link_info_num_list[$link_date_i]['ip']=$sum_ip-$between_sum_ip;
						    $link_info_num_list[$link_date_i]['uv']=$sum_uv-$between_sum_uv;
					    }
					    
					}
				}
 
			   $_SESSION['link_info_num_list']=$link_info_num_list;

   	    
    	    /**
    	     * 图
    	     */
			    	Vendor('jpgraph.jpgraph');
			    	Vendor('jpgraph.jpgraph_line');
			    	$aAxisType = 'intlin'; //第一个int是X轴类型第2个lin是Y轴类型
					$yScaleMin = 0; //Y轴最小值, 如果不需要设置，可以为空，或者NULL，下同
					$yScaleMax = $_SESSION['yScaleMax']; //Y轴最大值
					$xScaleMin = 1; //X轴最大值
					$xScaleMax = 24; //X轴最大值
					
					$unitType = '小时';
					
					  $chartDataTmpArr = array('1' =>$_SESSION['day_list']['01']['pv'], 
					  							'2' =>$_SESSION['day_list']['02']['pv'], 
					  							'3' =>$_SESSION['day_list']['03']['pv'], 
					  							'4' =>$_SESSION['day_list']['04']['pv'], 
					  							'5' =>$_SESSION['day_list']['05']['pv'], 
					  							'6' =>$_SESSION['day_list']['06']['pv'], 
					  							'7' =>$_SESSION['day_list']['07']['pv'], 
					  							'8' =>$_SESSION['day_list']['08']['pv'], 
					  							'9' => $_SESSION['day_list']['09']['pv'], 
					  							'10' =>$_SESSION['day_list']['10']['pv'], 
					  							'11' =>$_SESSION['day_list']['11']['pv'], 
					  							'12' =>$_SESSION['day_list']['12']['pv'], 
					  							'13' =>$_SESSION['day_list']['13']['pv'], 
					  							'14' =>$_SESSION['day_list']['14']['pv'], 
					  							'15' =>$_SESSION['day_list']['15']['pv'], 
					  							'16' =>$_SESSION['day_list']['16']['pv'], 
					  							'17' =>$_SESSION['day_list']['17']['pv'], 
					  							'18' =>$_SESSION['day_list']['18']['pv'], 
					  							'19' =>$_SESSION['day_list']['19']['pv'], 
					  							'20' =>$_SESSION['day_list']['20']['pv'], 
					  							'21' =>$_SESSION['day_list']['21']['pv'], 
					  							'22' =>$_SESSION['day_list']['22']['pv'], 
					  							'23' =>$_SESSION['day_list']['23']['pv'], 
					  							'24' =>$_SESSION['day_list']['24']['pv'],
					  							'25' => '1000000000');
					
					$chartDataTmpArr2 = array('1' =>$_SESSION['day_list']['01']['ip'], 
					  							'2' =>$_SESSION['day_list']['02']['ip'], 
					  							'3' =>$_SESSION['day_list']['03']['ip'], 
					  							'4' =>$_SESSION['day_list']['04']['ip'], 
					  							'5' =>$_SESSION['day_list']['05']['ip'], 
					  							'6' =>$_SESSION['day_list']['06']['ip'], 
					  							'7' =>$_SESSION['day_list']['07']['ip'], 
					  							'8' =>$_SESSION['day_list']['08']['ip'], 
					  							'9' => $_SESSION['day_list']['09']['ip'], 
					  							'10' =>$_SESSION['day_list']['10']['ip'], 
					  							'11' =>$_SESSION['day_list']['11']['ip'], 
					  							'12' =>$_SESSION['day_list']['12']['ip'], 
					  							'13' =>$_SESSION['day_list']['13']['ip'], 
					  							'14' =>$_SESSION['day_list']['14']['ip'], 
					  							'15' =>$_SESSION['day_list']['15']['ip'], 
					  							'16' =>$_SESSION['day_list']['16']['ip'], 
					  							'17' =>$_SESSION['day_list']['17']['ip'], 
					  							'18' =>$_SESSION['day_list']['18']['ip'], 
					  							'19' =>$_SESSION['day_list']['19']['ip'], 
					  							'20' =>$_SESSION['day_list']['20']['ip'], 
					  							'21' =>$_SESSION['day_list']['21']['ip'], 
					  							'22' =>$_SESSION['day_list']['22']['ip'], 
					  							'23' =>$_SESSION['day_list']['23']['ip'], 
					  							'24' =>$_SESSION['day_list']['24']['ip'],
					  							'25' => '1000000000');		
					$chartDataTmpArr3 = array('1' =>$_SESSION['day_list']['01']['uv'], 
					  							'2' =>$_SESSION['day_list']['02']['uv'], 
					  							'3' =>$_SESSION['day_list']['03']['uv'], 
					  							'4' =>$_SESSION['day_list']['04']['uv'], 
					  							'5' =>$_SESSION['day_list']['05']['uv'], 
					  							'6' =>$_SESSION['day_list']['06']['uv'], 
					  							'7' =>$_SESSION['day_list']['07']['uv'], 
					  							'8' =>$_SESSION['day_list']['08']['uv'], 
					  							'9' => $_SESSION['day_list']['09']['uv'], 
					  							'10' =>$_SESSION['day_list']['10']['uv'], 
					  							'11' =>$_SESSION['day_list']['11']['uv'], 
					  							'12' =>$_SESSION['day_list']['12']['uv'], 
					  							'13' =>$_SESSION['day_list']['13']['uv'], 
					  							'14' =>$_SESSION['day_list']['14']['uv'], 
					  							'15' =>$_SESSION['day_list']['15']['uv'], 
					  							'16' =>$_SESSION['day_list']['16']['uv'], 
					  							'17' =>$_SESSION['day_list']['17']['uv'], 
					  							'18' =>$_SESSION['day_list']['18']['uv'], 
					  							'19' =>$_SESSION['day_list']['19']['uv'], 
					  							'20' =>$_SESSION['day_list']['20']['uv'], 
					  							'21' =>$_SESSION['day_list']['21']['uv'], 
					  							'22' =>$_SESSION['day_list']['22']['uv'], 
					  							'23' =>$_SESSION['day_list']['23']['uv'], 
					  							'24' =>$_SESSION['day_list']['24']['uv'],
					  							'25' => '1000000000');		
					$graph = new Graph($width = 750 , $height = 300); //创建新的Graph对象
					$graph->SetScale($aAxisType, $yScaleMin, $yScaleMax, $xScaleMin, $xScaleMax); //设置刻度模式SetScale($aAxisType,$aYMin=1,$aYMax=1,$aXMin=1,$aXMax=1)
					
					$graph->img->SetMargin(40, 20, 50, 50) ; //设置图表边界
					$title = date("Y-m-d H:i:s")."统计图";
					$graph->title->SetFont(FF_SIMSUN,FS_BOLD); //设置图表标题的字体类型
					$graph->title->Set($wholeTitle);
					$graph->title->SetMargin (20);
					
					$graph->xaxis->title->SetFont(FF_SIMSUN);
					$graph->xaxis->title->Set($unitType);
					$graph->xaxis->title->SetMargin(14);
					
					$graph->legend->SetLineWeight(2); //设置图例文字的字体 
					
					$lineplot = new LinePlot($chartDataTmpArr); //创建要画的一地条曲线的对象
					$lineplot->SetWeight(2); //曲线的线宽
					
					$lineplot->SetLegend("pv");//设置图例文字
					$graph->legend->Pos( 0.025, 0.08, "right","center" ); //图例文字框的位置 0.025，0.08 是以右上角为基准的，0.025是距左右距离，0.08是上下距离。
					$graph->legend->SetLayout('1'); //如果有两条曲线，他们的图例文字并排放置。
					$graph->legend->SetFrameWeight(0); //图例文字外框边框border设置为0
					$graph->legend->SetFillColor('#C8C8C8'); //图例文字框内的填充颜色
					$graph->legend->SetShadow('#C8C8C8', 0); //设置图例文字框的阴影部分颜色和border
					$lineplot->SetColor("orange"); //设置曲线颜色
					$graph->Add($lineplot); //在统计图上绘制曲线
					    
					$lineplot2 = new LinePlot($chartDataTmpArr2); //创建一条新的曲线对象
					$lineplot2->SetLegend("ip");
					$lineplot2->SetWeight(2);
					$lineplot2->SetColor("blue"); 
					$graph->Add($lineplot2);
					
					$lineplot3 = new LinePlot($chartDataTmpArr3); //创建一条新的曲线对象
					$lineplot3->SetLegend("uv");
					$lineplot3->SetWeight(2);
					$lineplot3->SetColor("red"); 
					$graph->Add($lineplot3);
					
					$_SESSION['filename']=THEME_PATH.'Public/images/strock/'.time().'.png';		
					$graph->Stroke($_SESSION['filename']);
			//		$view_html=$graph->Stroke();
    	    }
    	    if($_POST['in_pv_ip_uv']){//pv_ip_uv排序
    	    	foreach ($_SESSION['day_list'] as $key => $row) {
			    $volume[$key]  = $row[$_POST['in_pv_ip_uv']];  
				}
				array_multisort($volume, SORT_DESC, $_SESSION['day_list']);
    	    }
 
    	    		    	
//		dump($_SESSION['day_list']);
	
    	$this->assign('show_date',$_SESSION['show_date']);
		$this->assign('app_id',$app_id);
		$this->assign('app_name',$app_name);
		$this->assign('view_html',$_SESSION['filename']);
		$this->assign('link_info_num_list',$_SESSION['link_info_num_list']);
		$this->assign('list',$_SESSION['day_list']);// 赋值数据集
		$this->display();
    }
    
    public function add_link(){
    	$tianjia_html='';
    	$this->display();
    }
    
    public function add_link_operation(){
	    if ($_POST['app_name']){
				$info_add_model=M('App_info');
				$vo=$info_add_model->create();
				if ($vo) {
		            if (false !== $info_add_model->add()) {
		            	$app_id=$info_add_model->getLastInsID();
		            	//创建ip表
		            	$ip_Model = new Model();
		            	$table="app_table_ip_".$app_id;
		            	$sql_ip="CREATE TABLE $table (
		            								`app_table_ip_id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
		            								`app_id` INT(11) NOT NULL ,
		            								`app_date` VARCHAR(25) NOT NULL ,
		            								`01` INT(11) NOT NULL ,
		            								`02` INT(11) NOT NULL ,
		            								`03` INT(11) NOT NULL ,
		            								`04` INT(11) NOT NULL ,
		            								`05` INT(11) NOT NULL ,
		            								`06` INT(11) NOT NULL ,
		            								`07` INT(11) NOT NULL ,
		            								`08` INT(11) NOT NULL ,
		            								`09` INT(11) NOT NULL ,
		            								`10` INT(11) NOT NULL ,
		            								`11` INT(11) NOT NULL ,
		            								`12` INT(11) NOT NULL ,
		            								`13` INT(11) NOT NULL ,
		            								`14` INT(11) NOT NULL ,
		            								`15` INT(11) NOT NULL ,
		            								`16` INT(11) NOT NULL ,
		            								`17` INT(11) NOT NULL ,
		            								`18` INT(11) NOT NULL ,
		            								`19` INT(11) NOT NULL ,
		            								`20` INT(11) NOT NULL ,
		            								`21` INT(11) NOT NULL ,
		            								`22` INT(11) NOT NULL ,
		            								`23` INT(11) NOT NULL ,
		            								`24` INT(11) NOT NULL ,
		            								`aggregate` INT(11) NOT NULL )";
		            	$ip_Model->query($sql_ip);
		            	//创建pv表
		            	$pv_Model = new Model();
		            	$table="app_table_pv_".$app_id;
		            	$sql_pv="CREATE TABLE $table (
		            								`app_table_pv_id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
		            								`app_id` INT(11) NOT NULL ,
		            								`app_date` VARCHAR(25) NOT NULL ,
		            								`01` INT(11) NOT NULL ,
		            								`02` INT(11) NOT NULL ,
		            								`03` INT(11) NOT NULL ,
		            								`04` INT(11) NOT NULL ,
		            								`05` INT(11) NOT NULL ,
		            								`06` INT(11) NOT NULL ,
		            								`07` INT(11) NOT NULL ,
		            								`08` INT(11) NOT NULL ,
		            								`09` INT(11) NOT NULL ,
		            								`10` INT(11) NOT NULL ,
		            								`11` INT(11) NOT NULL ,
		            								`12` INT(11) NOT NULL ,
		            								`13` INT(11) NOT NULL ,
		            								`14` INT(11) NOT NULL ,
		            								`15` INT(11) NOT NULL ,
		            								`16` INT(11) NOT NULL ,
		            								`17` INT(11) NOT NULL ,
		            								`18` INT(11) NOT NULL ,
		            								`19` INT(11) NOT NULL ,
		            								`20` INT(11) NOT NULL ,
		            								`21` INT(11) NOT NULL ,
		            								`22` INT(11) NOT NULL ,
		            								`23` INT(11) NOT NULL ,
		            								`24` INT(11) NOT NULL ,
		            								`aggregate` INT(11) NOT NULL )";
		            	$pv_Model->query($sql_pv);
		            	//创建uv表
		            	$uv_Model = new Model();
		            	$table="app_table_uv_".$app_id;
		            	$sql_uv="CREATE TABLE $table (
		            								`app_table_uv_id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
		            								`app_id` INT(11) NOT NULL ,
		            								`app_date` VARCHAR(25) NOT NULL ,
		            								`01` INT(11) NOT NULL ,
		            								`02` INT(11) NOT NULL ,
		            								`03` INT(11) NOT NULL ,
		            								`04` INT(11) NOT NULL ,
		            								`05` INT(11) NOT NULL ,
		            								`06` INT(11) NOT NULL ,
		            								`07` INT(11) NOT NULL ,
		            								`08` INT(11) NOT NULL ,
		            								`09` INT(11) NOT NULL ,
		            								`10` INT(11) NOT NULL ,
		            								`11` INT(11) NOT NULL ,
		            								`12` INT(11) NOT NULL ,
		            								`13` INT(11) NOT NULL ,
		            								`14` INT(11) NOT NULL ,
		            								`15` INT(11) NOT NULL ,
		            								`16` INT(11) NOT NULL ,
		            								`17` INT(11) NOT NULL ,
		            								`18` INT(11) NOT NULL ,
		            								`19` INT(11) NOT NULL ,
		            								`20` INT(11) NOT NULL ,
		            								`21` INT(11) NOT NULL ,
		            								`22` INT(11) NOT NULL ,
		            								`23` INT(11) NOT NULL ,
		            								`24` INT(11) NOT NULL ,
		            								`aggregate` INT(11) NOT NULL )";
		            	$uv_Model->query($sql_uv);
		            	//添加连接
				            if ($app_id){
				            	$_POST['app_id']=$app_id;
								$link_add_model=M('App_link');
								$vo=$link_add_model->create();
								if ($vo) {
						            if (false !== $link_add_model->add()) {
						                $this->redirect('Dataflow/index', array(),1,'<script language="JavaScript">alert("添加成功")</script>');
						            } else {
						                $this->error("添加失败");
						            }
						        } else {
						            header("Content-Type:text/html; charset=utf-8");
						            $this->error($link_add_model->getError().' [ <a href="javascript:history.back()">return</a> ]');
						            exit();
						        }
							}
		                $this->redirect('Dataflow/index', array(),1,'<script language="JavaScript">alert("添加成功")</script>');
		            } else {
		                $this->error("添加失败");
		            }
		        } else {
		            header("Content-Type:text/html; charset=utf-8");
		            $this->error($info_add_model->getError().' [ <a href="javascript:history.back()">return</a> ]');
		            exit();
		        }
			}
    	
    }
    
	protected function _list($modelname, $map = '', $field = '*',$asc = false ,$listRows = 100) {
		
		$count = $modelname->where($map)->count();
		if($count>0){
			import ( "@.ORG.Page" );
			$sort = $asc ? 'asc' : 'desc';
			$p = new Page ($count, $listRows );
			$page =$p->show();

			$_SESSION['volist']=$voList = $modelname->field($field)->where($map)->order($asc)->limit($p->firstRow . ','.$p->listRows)->select();			
//			dump($voList);
			
 			$this->assign('page',$page);// 赋值分页输出
		}
	}
	
	public function edit_index(){
		/**
		 * 启用禁止
		 */
		if ($_GET['app_link_qiyong1']){
			$app_id=$_GET['app_id'];
			$app_link_model=M('app_link');
			$data['app_link_qiyong1']=$_GET['app_link_qiyong1'];
			$list=$app_link_model->where("app_id='".$app_id."'")->save($data);
		}
		if ($_GET['app_link_qiyong2']){
			$app_id=$_GET['app_id'];
			$app_link_model=M('app_link');
			$data['app_link_qiyong2']=$_GET['app_link_qiyong2'];
			$list=$app_link_model->where("app_id='".$app_id."'")->save($data);
		}
		if ($_GET['app_link_qiyong3']){
			$app_id=$_GET['app_id'];
			$app_link_model=M('app_link');
			$data['app_link_qiyong3']=$_GET['app_link_qiyong3'];
			$list=$app_link_model->where("app_id='".$app_id."'")->save($data);
		}
		if ($_GET['app_link_qiyong4']){
			$app_id=$_GET['app_id'];
			$app_link_model=M('app_link');
			$data['app_link_qiyong4']=$_GET['app_link_qiyong4'];
			$list=$app_link_model->where("app_id='".$app_id."'")->save($data);
		}
		if ($_GET['app_link_qiyong5']){
			$app_id=$_GET['app_id'];
			$app_link_model=M('app_link');
			$data['app_link_qiyong5']=$_GET['app_link_qiyong5'];
			$list=$app_link_model->where("app_id='".$app_id."'")->save($data);
		}
		
		/**
		 * 
		 * 页面显示
		 * 
		 */
		$app_id=$_GET['app_id'];
		$app_info_guanlian_model=D('Admin/App_info');
		$app_info_guanlian = $app_info_guanlian_model->relation(true)->where("id='".$app_id."'")->select();
		
		$js_i=0;
		if(!empty($app_info_guanlian[0]['app_link'][0]['app_link_ad2'])){$js_i=1;}
		if(!empty($app_info_guanlian[0]['app_link'][0]['app_link_ad3'])){$js_i=2;}
		if(!empty($app_info_guanlian[0]['app_link'][0]['app_link_ad4'])){$js_i=3;}
		if(!empty($app_info_guanlian[0]['app_link'][0]['app_link_ad5'])){$js_i=4;}
		

		$this->assign('js_i',$js_i);
		$this->assign('app_id',$app_id);
		$this->assign('app_info',$app_info_guanlian);
		$this->display();
	}
	
	public function edit_link_operation(){
		$app_info_guanlian_model=D('Admin/App_info');
		$app_id=$_POST['app_id'];
		$app_link_id=$_POST['app_link_id'];
		
		$data['app_name']=$_POST['app_name'];
        $data['app_sort']=$_POST['app_sort'];
        $data['app_link']=array(
                          array('app_link_id'=>$app_link_id,'app_link_alias1'=>$_POST['app_link_alias1'],'app_link_ad1'=>$_POST['app_link_ad1'],'app_link_start1'=>$_POST['app_link_start1'],'app_link_sed1'=>$_POST['app_link_sed1'],
                          		'app_link_alias2'=>$_POST['app_link_alias2'],'app_link_ad2'=>$_POST['app_link_ad2'],'app_link_start2'=>$_POST['app_link_start2'],'app_link_sed2'=>$_POST['app_link_sed2'],
                          		'app_link_alias3'=>$_POST['app_link_alias3'],'app_link_ad3'=>$_POST['app_link_ad3'],'app_link_start3'=>$_POST['app_link_start3'],'app_link_sed3'=>$_POST['app_link_sed3'],
                          		'app_link_alias4'=>$_POST['app_link_alias4'],'app_link_ad4'=>$_POST['app_link_ad4'],'app_link_start4'=>$_POST['app_link_start4'],'app_link_sed4'=>$_POST['app_link_sed4'],
                          		'app_link_alias5'=>$_POST['app_link_alias5'],'app_link_ad5'=>$_POST['app_link_ad5'],'app_link_start5'=>$_POST['app_link_start5'],'app_link_sed5'=>$_POST['app_link_sed5'],
//                          		'app_link_qiyong1'=>$_POST['app_link_qiyong1'],'app_link_qiyong2'=>$_POST['app_link_qiyong2'],'app_link_qiyong3'=>$_POST['app_link_qiyong3'],'app_link_qiyong4'=>$_POST['app_link_qiyong4'],'app_link_qiyong5'=>$_POST['app_link_qiyong5']
                          ),
//                          array('id'=>2,'title'=>'燕子'),
                      );
        //关联更新
       $list=$app_info_guanlian_model->relation(true)->where("id='".$app_id."'")->save($data);
       
       
		 if (false !== $list) {
				$this->redirect('Dataflow/index', array(),1,'<script language="JavaScript">alert("修改成功")</script>');
		} else {
                $this->error("修改失败");
		}
		
	}
	
	private function date_sum($startdate,$enddate){
				$info_model=M('App_info');
    			$this->_list($info_model);
    			$data['app_date'] = array('between', array($startdate, $enddate));
    			foreach ($_SESSION['volist'] as $key => $value){
		    		$app_table_ip="app_table_ip_".$value['id'];
					$app_table_ip_model = M($app_table_ip); 
					$app_table_ip_info=$app_table_ip_model->where($data)->sum('aggregate');
					if (!$app_table_ip_info){
						$app_table_ip_info=0;
					}
					
		    		$_SESSION['volist'][$key]['ip']=$app_table_ip_info;
		    		
		    		$app_table_pv="app_table_pv_".$value['id'];
					$app_table_pv_model = M($app_table_pv); 
					$app_table_pv_info=$app_table_pv_model->where($data)->sum('aggregate');
					if (!$app_table_pv_info){
						$app_table_pv_info=0;
					}
					
		    		$_SESSION['volist'][$key]['pv']=$app_table_pv_info;
		    		
		    		$app_table_uv="app_table_uv_".$value['id'];
					$app_table_uv_model = M($app_table_uv); 
					$app_table_uv_info=$app_table_uv_model->where($data)->sum('aggregate');
					if (!$app_table_uv_info){
						$app_table_uv_info=0;
					}
					
		    		$_SESSION['volist'][$key]['uv']=$app_table_uv_info;
    			}
	}
	
	private function fenyie($arr_val,$get_page=2,$listRows=3){			
			$pnum = ceil(count($arr_val) / $listRows);
			if(isset($get_page)){
			    $page = intval($get_page);
			    $page = $page > $pnum? $pnum: $page;
			    $page = $page < $pnum? 1: $page;
			}else{
			    $page = 1;
			}
			for($i = 0; $i < $listRows; $i++){
			    if(!isset($arr_val[($page - 1) * $listRows + $i]))break;
			    $data_list[]=$arr_val[($page - 1) * $listRows + $i];
			}
//			dump($page);
			$this->assign('data_list',$data_list);
	}
	
	protected function _list2($modelname, $map = '', $field = '*',$asc = false ,$listRows = 30) {
		
		$count = $modelname->where($map)->count();
		if($count>0){
			import ( "@.ORG.Page" );
			$sort = $asc ? 'asc' : 'desc';
			$p = new Page ($count, $listRows );
			$page =$p->show();

			$_SESSION['volist2']=$voList = $modelname->field($field)->where($map)->order('app_date desc')->limit($p->firstRow . ','.$p->listRows)->select();			
			
			
 			$this->assign('page',$page);// 赋值分页输出
		}else {
			unset($_SESSION['volist2']);
		}
	}
	
	 
}